package com.fau.template.service.impl;

import java.util.Map;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.fau.template.entity.NmRole;
import com.fau.template.service.IRoleManagerService;
import com.fau.template.util.Page;

@Service
@Transactional(readOnly = true)
public class RoleManagerServiceImpl extends BaseService implements
		IRoleManagerService {

	@Override
	public Page findRolesByPage(Map<String, Object> map, NmRole role) {
		return null;
	}

	@Override
	@Transactional(readOnly = false, propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
	public void save(NmRole role) {
		this.iBaseDao.insertObject(role);
	}

	@Override
	@Transactional(readOnly = false, propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
	public void delete(NmRole role) {
		String[] ids = role.getId().split("-");
		for(String id : ids) {
			this.iBaseDao.updateByHql("delete from NmRole r where r.id = ? ", id);
		}
	}

	@Override
	@Transactional(readOnly = false, propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
	public void update(NmRole role) {
		this.iBaseDao.updateObject(role);
	}

	@Override
	public NmRole getRoleById(String id) {
		return (NmRole) this.iBaseDao.getObject(NmRole.class, id);
	}

}
